{% extends "teacher/teacher.html" %}

{% block app_content %}
    <div class="container mb-4"></div>
    {% if course_tables %}
    {% for course_table in course_tables %}
    <div class="container mb-5">
    <hr>
    <p class="lead CourseNum"><strong>课程号：</strong><font>{{ course_table[0].CourseNum }}</font></p>
    <p class="lead"><strong>课程名：</strong>{{ course_table[0].CourseName }}</p>
    <p class="lead"><strong>选课人数：</strong>{{ course_table[0].CourseStudents }}</p>
    <form action="/course_grade_input/" method="POST" class="form-signin">
        <table class="table table-striped table-hover">
            <thead class="thead-dark">
            <tr>
                <th class="lead">学号</th>
                <th class="lead">姓名</th>
                <th class="lead">性别</th>
                <th class="lead">学院</th>
                <th class="lead">专业</th>
                <th class="lead">成绩</th>
            </tr>
            </thead>
            <tbody>
            {% if course_table[1] %}
            {% for table in course_table[1] %}
            <tr>
            <td class="lead StudentNum">{{ table.StudentNum }}</td>
            <td class="lead">{{ table.StudentName }}</td>
            <td class="lead">{{ table.StudentSex }}</td>
            <td class="lead">{{ table.DeptName }}</td>
            <td class="lead">{{ table.MajorName }}</td>
            {% if table.Grade %}
                {% if table.Grade < 60 %}
                <td class="lead table-danger">
                    <div class="row clearfix">
                        <div class="col-md-5 column">
                            <strong>{{ table.Grade }}</strong>
                        </div>
                        <div class="col-md-7 column">
                            <a  class="btn btn-primary btn-sm" href="{{ url_for('grade_set_zero', CourseNum=course_table[0].CourseNum, StudentNum=table.StudentNum) }}">重置成绩</a>
                        </div>
                    </div>
                </td>
                {% else %}
                <td class="lead">
                    <div class="row clearfix">
                        <div class="col-md-5 column">
                            <strong>{{ table.Grade }}</strong>
                        </div>
                        <div class="col-md-7 column">
                            <a  class="btn btn-outline-danger btn-sm" href="{{ url_for('grade_set_zero', CourseNum=course_table[0].CourseNum, StudentNum=table.StudentNum) }}">重置成绩</a>
                        </div>
                    </div>
                </td>
                {% endif %}
            {% else %}
            <td class="lead">
                <div class="input-group input-group-sm"> 
                    <input type="number" class="form-control" max=100 min=0 required>
                </div>
            </td>
            {% endif %}
            </tr>
            {% endfor %}
            {% endif %}
            </tbody>
        </table>
        
        <div class="row">
            <div class="col-md-12 column">
                {% if course_table[2] %}
                <button type="submit" class="btn btn-outline-success btn-lg btn-block">确认录入</button>
                {% else %}
                <button type="submit" class="btn btn-secondary btn-lg btn-block" disabled>已录入完成</button>
                {% endif %}
            </div>
        </div>
        
    </form>
    </div>
{% endfor %}
{% endif %}
{% endblock %}

{% block scripts %}
{{super()}}
<script>
    $(document).ready(function(){
        var divs = $('div.mb-5')
        divs.each(function(){
            //alert($(this).find('font').text())
            $(this).find('form').attr('action', function(i,origValue){
                return origValue + $(this).parent().find('font').text()
            })
        })
    }
    )
</script>
<script>
    $(document).ready(function(){
        var tables = $('table')
        tables.each(function(){
            var td_StudentNum = $(this).find('td.StudentNum')
            td_StudentNum.each(function(){
            $(this).siblings().last().find('input').attr('name',$(this).text());
            })
        })
    })
</script>
{% endblock %}